package com.zy.smarthome.frame.util;

/**
 * @author Administrator
 */
public class CmdUtils {

    /**
     * 计算和校验值
     *
     * @param body
     * @return
     */
    public static String getCmdBodySum(String body) {
        int sum = 0;
        for (int i = 0; i < body.length(); i += 2) {
            sum += Integer.parseInt(body.substring(i, i + 2), 16);
        }
        sum = sum & 0xff;
        String hexStr = Integer.toHexString(sum);
        if (hexStr.length() == 1) {
            hexStr = "0" + hexStr;
        }
        return hexStr.toUpperCase();
    }

}
